package com.atguigu.bigdata.spark.core.rdd.operator.transform;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.VoidFunction;

import java.util.Arrays;
import java.util.List;
/* map转换算子把原数值乘以2 */
public class Spark01_RDD_Operator_Transform_JAVA {
    public static void main(String[] args) {
        // TODO 准备环境
        SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("sparkCore");
        JavaSparkContext sc = new JavaSparkContext(conf);
        // TODO 创建RDD
        // 从内存中创建RDD，将内存中集合的数据作为处理的数据源  使用parallelize
        List<Integer> seq = Arrays.asList(1,2,3,4,5);
        JavaRDD<Integer> rdd = sc.parallelize(seq);

        JavaRDD<Integer> maprdd = rdd.map(new Function<Integer, Integer>() {
            @Override
            public Integer call(Integer integer) throws Exception {
                return integer * 2;
            }
        });

        maprdd.foreach(new VoidFunction<Integer>() {
            @Override
            public void call(Integer integer) throws Exception {
                System.out.println(integer);
            }
        });

        sc.stop();

    }
}
